Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Add example for gemini 1.5 #24

Closed
wants to merge 3 commits into from

Conversation

gabrielchua
Copy link

Added an example for Gemini 1.5, based on the Google Generative AI SDK.

Copy link

vercel bot commented May 20, 2024

Someone is attempting to deploy a commit to the E2B Team on Vercel.

A member of the Team first needs to authorize it.

@mlejva
Copy link
Member

mlejva commented May 21, 2024

Hi @gabrielchua, have you actually ran the code? There are several errors that prevent it from actually working

@gabrielchua
Copy link
Author

Hi @mlejva yes - I did run the code - https://github.com/gabrielchua/e2b-cookbook/blob/main/examples/gemini-1.5-code-interpreter/gemini-1.5.ipynb

What are the errors you’re getting?

i realised it may not be clear that this is using Google AI Studio, and not Vertex AI. The former’s for non-GCP users

@mlejva
Copy link
Member

mlejva commented May 21, 2024

Hi @mlejva yes - I did run the code - https://github.com/gabrielchua/e2b-cookbook/blob/main/examples/gemini-1.5-code-interpreter/gemini-1.5.ipynb

What are the errors you’re getting?

i realised it may not be clear that this is using Google AI Studio, and not Vertex AI. The former’s for non-GCP users

I'm getting an error related to how you're passing the exec_python_code as a tool:

import google.generativeai as genai

# Configure the API key
genai.configure(api_key=GOOGLE_API_KEY)

# Initialize the model, and pass the system instruction and tools
model = genai.GenerativeModel(model_name=MODEL_NAME,
                              system_instruction=SYSTEM_PROMPT,
                              tools=[execute_python_code])
---------------------------------------------------------------------------
PydanticSchemaGenerationError             Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/google/generativeai/types/content_types.py in _make_tool(tool)
    700         try:
--> 701             return Tool(function_declarations=[tool])
    702         except Exception as e:

29 frames
PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'e2b_code_interpreter.main.CodeInterpreter'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.

For further information visit https://errors.pydantic.dev/2.7/u/schema-for-unknown-type

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/google/generativeai/types/content_types.py in _make_tool(tool)
    701             return Tool(function_declarations=[tool])
    702         except Exception as e:
--> 703             raise TypeError(
    704                 "Expected an instance of `genai.ToolType`. Got a:\n" f"  {type(tool)=}",
    705                 tool,

TypeError: ("Expected an instance of `genai.ToolType`. Got a:\n  type(tool)=<class 'function'>", <function execute_python_code at 0x7cb02d303d90>)

@gabrielchua
Copy link
Author

gabrielchua commented May 21, 2024

Locally, I'm using Python 3.11 with the following packages, and it runs.

e2b==0.17.0
e2b-code-interpreter==0.0.6
google-generativeai==0.5.4
pydantic==2.7.1

I've tried the notebook in Co-Lab too (see here). The co-lab runtime uses Python 3.10 with the following:

(same as above)

e2b==0.17.0
e2b-code-interpreter==0.0.6
google-generativeai==0.5.4
pydantic==2.7.1

@tizkovatereza
Copy link
Member

tizkovatereza commented Jun 5, 2024

Locally, I'm using Python 3.11 with the following packages, and it runs.

e2b==0.17.0
e2b-code-interpreter==0.0.6
google-generativeai==0.5.4
pydantic==2.7.1

I've tried the notebook in Co-Lab too (see here). The co-lab runtime uses Python 3.10 with the following:

(same as above)

e2b==0.17.0
e2b-code-interpreter==0.0.6
google-generativeai==0.5.4
pydantic==2.7.1

Hey @gabrielchua !
I tested it and getting this error (and it doesn't work either in the Google Collab).
I'm not sure what's the issue now, can you please check it? (I tried it with the same packages versions.)

Otherwise the code looks good!

Screenshot 2024-06-05 at 17 46 08 Screenshot 2024-06-05 at 17 46 36

@gabrielchua gabrielchua closed this by deleting the head repository Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants